package model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;

public class resources {

    private int Rid;

    private String Rname;

    private String Ucate;

    private String Rurl;

    public int getRid() {
        return Rid;
    }

    public void setRid(int rid) {
        Rid = rid;
    }

    public String getRname() {
        return Rname;
    }

    public void setRname(String rname) {
        Rname = rname;
    }

    public String getUcate() {
        return Ucate;
    }

    public void setUcate(String ucate) {
        Ucate = ucate;
    }

    public static HashMap<String,String> findResourceByCate(String cate){

        Connection con=jdbcUtil.jdbcUtil.getConnection();

        PreparedStatement pstm=null;

        ResultSet rs=null;

        //HashSet<String> nature=new HashSet<>();
        HashMap<String,String> nature=new HashMap<>();

        try {

           //!!!!! System.out.println("---->problem--->resources.java");
            pstm=con.prepareStatement("SELECT * FROM resources WHERE Ucate=?");

            pstm.setString(1,cate);

            rs=pstm.executeQuery();

            while (rs.next()){
                String temp=rs.getString("Rname");
                String temp2=rs.getString("Rurl");
                nature.put(temp,temp2);
            }

        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("---->problem--->resources.java");
        }
        return nature;


    }
}
